function [] = saveQMTMinc(qmt_mat_file,base_minc_image, output_filename)
%SAVEQMTMINC Summary of this function goes here
%   Detailed explanation goes here

load(qmt_mat_file)

[hdr,~] = niak_read_minc([cd, '/', base_minc_image]);

fMap=zeros(hdr.info.dimensions(1),hdr.info.dimensions(2),hdr.info.dimensions(3));

fit.mask=fit.mask(:);

bb=0;
for ii=1:length(fit.mask)
    if fit.mask(ii)==1
        bb=bb+1;            
        fMap(ii)=fit.f(bb);        
    end
    
    if bb == length(fit.f)
        break;
    end

end

fMap = reshape(fMap,hdr.info.dimensions(1),hdr.info.dimensions(2),hdr.info.dimensions(3));

fMap(fMap>1)=0;
fMap2=imrotate_3D(fMap,180);

f_hdr = hdr;
f_hdr.file_name = output_filename;
save('fMap.mat','fMap2')
niak_write_minc(f_hdr,fMap2);

end

